import { db } from "./db";

export class LibrarieService {
    static async one(url: string) {
        return await db.resources.where('key').equals(url).first()
    }

    static async save(data: ScriptResourceInfo) {
        const temp = await db.resources.get(data.id);
        if (temp) {
            await db.resources.update(data.id, {
                ...data
            })
        } else {
            await db.resources.add(data)
        }
    }

    static async remove(url: string) {
        return db.resources.where('key').equals(url).delete()
    }

    static clear(){
        return db.resources.clear()
    }
}